/*
 * FileName: csmartptr.cc
 * Author: 李波(Edwin Lee)
 * Date: 2024-07-05 15:14:11
 * Version: 1.0
 * Description:智能指针类
 */
#include <iostream>
#include <memory>
using namespace std;

template <typename T>
class CSmartPtr
{
public:
	CSmartPtr(T* ptr = nullptr)
		:mptr(ptr){}
	~CSmartPtr()
	{
		if(nullptr != mptr)
			delete mptr;
	}
	T& operator*()
	{
		return *mptr;
	}
	T* operator->()
	{
		return mptr;
	}
private:
	T* mptr;
};

class Test 
{
public:
	void echo()
	{
		cout<<"call Test::echo"<<endl;
	}
};
int main()
{
	CSmartPtr<int> intptr(new int);
	*intptr = 100;
	cout<<"*intptr"<<*intptr<<endl;
	CSmartPtr<Test> testptr(new Test);
	testptr->echo();
	return 0;
}
